package com.example.accessibilitydemo.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PreferenceUtil {
	private static SharedPreferences.Editor mEditor = null;
	private static SharedPreferences mSharedPreferences = null;

	public static void init(Context paramContext) {
		if (mSharedPreferences == null)
			mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
	}
	
	public static void commitBoolean(String key, boolean value) {
		mEditor = mSharedPreferences.edit();
		mEditor.putBoolean(key, value);
		mEditor.commit();
	}

	public static void commitInt(String key, int value) {
		mEditor = mSharedPreferences.edit();
		mEditor.putInt(key, value);
		mEditor.commit();
	}

	public static void commitLong(String key, long value) {
		mEditor = mSharedPreferences.edit();
		mEditor.putLong(key, value);
		mEditor.commit();
	}

	public static void commitString(String key, String value) {
		mEditor = mSharedPreferences.edit();
		mEditor.putString(key, value);
		mEditor.commit();
	}

	public static Boolean getBoolean(String key, boolean defaultValue) {
		return Boolean.valueOf(mSharedPreferences.getBoolean(key, defaultValue));
	}

	public static int getInt(String key, int defaultValue) {
		return mSharedPreferences.getInt(key, defaultValue);
	}

	public static long getLong(String key, long defaultValue) {
		return mSharedPreferences.getLong(key, defaultValue);
	}

	public static String getString(String key, String defaultValue) {
		return mSharedPreferences.getString(key, defaultValue);
	}

	public static void removeAll() {
		mEditor = mSharedPreferences.edit();
		mEditor.clear();
		mEditor.commit();
	}

	public static void removeKey(String paramString) {
		mEditor = mSharedPreferences.edit();
		mEditor.remove(paramString);
		mEditor.commit();
	}
}